package com.ruoyu.cloud.ai.chat.controller;

import com.ruoyu.cloud.ai.chat.respository.ChatHistoryRespository;
import com.ruoyu.cloud.ai.chat.service.CustomerSupportAssistant;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@CrossOrigin
@RestController
@RequestMapping("/ai/")
public class ChatController {

    //    private final ChatClient chatClient;
//
    private final ChatHistoryRespository chatHistoryRespository;

    private final CustomerSupportAssistant agent;

    /*@RequestMapping("chat")
    public String chat(String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .call().content();
    }*/

    @RequestMapping(value = "chat", produces = "text/html;charset=utf-8")
    public String chat(String question, String chatId) {
        //1.保存会话id
        chatHistoryRespository.save("chat", chatId);
        //2.请求模型
//        return chatClient.prompt()
//                .user(question)
//                .advisors(a -> a.param(CHAT_MEMORY_CONVERSATION_ID_KEY, chatId))
//                .stream()
//                .content();
        return agent.chat(chatId, question);
    }

    @RequestMapping("ping")
    public String chat() {
        return "pong";
    }
}
